package comits.web.client.servlets.demo;



import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import comits.business.tiers.dao.*;
import comits.business.tiers.metiers.*;
import comits.business.tiers.rp.tasks.ws.ControleurClassification;
import comits.business.tiers.utilitaires.Dates;





public class ModifierClassifServlet extends HttpServlet{
	
	/**
	 * 
	 * @author Dourga
	 */
	private static final long serialVersionUID = 7526928611471348888L;

	protected void processRequest(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	
	}
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		
		List<ListProduitVentes> listpV = (List<ListProduitVentes>) session.getAttribute("listpV");
		ControleurClassification ContClassif = new ControleurClassification();
		ContClassif.ValiderClassification(listpV);
		getServletContext().getRequestDispatcher("/ValiderClassif.jsp").forward(request, response);
		
		
	}
	
	
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String action = request.getParameter("action");
		HttpSession session = request.getSession();  	
		
	if(action.equals("ModifierA")){
			
			List<ListProduitVentes> listpV = (List<ListProduitVentes>) session.getAttribute("listpV");
			int k = Integer.parseInt(request.getParameter("site"));
			listpV.get(k).setClasse('A');
			request.setAttribute("listpV",listpV);
			getServletContext().getRequestDispatcher("/ResultatClassification.jsp").forward(request, response);
		}
		else if(action.equals("ModifierB")){
			
			List<ListProduitVentes> listpV = (List<ListProduitVentes>) session.getAttribute("listpV");
			
			int k = Integer.parseInt(request.getParameter("site"));
			listpV.get(k).setClasse('B');
			request.setAttribute("listpV",listpV);
			getServletContext().getRequestDispatcher("/ResultatClassification.jsp").forward(request, response);
		} 
		else if(action.equals("ModifierC")){
			
			List<ListProduitVentes> listpV = (List<ListProduitVentes>) session.getAttribute("listpV");
			int k = Integer.parseInt(request.getParameter("site"));
			listpV.get(k).setClasse('C');
			request.setAttribute("listpV",listpV);
			getServletContext().getRequestDispatcher("/ResultatClassification.jsp").forward(request, response);
		} 
		else {
			
			
		}
		
	}
	
	/**
	 * Returns a short description of the servlet.
	 * 
	 * @return a String containing servlet description
	 */
	public String getServletInfo() {
		return "Short description";
	}// </editor-fold>
}
 
